package com.faxsun.core.web.security;

import org.broadleafcommerce.profile.core.domain.Customer;
import org.broadleafcommerce.profile.web.core.security.CustomerStateRequestProcessor;
import org.springframework.security.cas.authentication.CasAuthenticationToken;
import org.springframework.security.core.Authentication;

public class FSCustomerStateRequestProcessor extends CustomerStateRequestProcessor {

	 /**
     * Subclasses can extend to resolve other types of Authentication tokens
     * @param authentication
     * @return
     */
	@Override
    public Customer resolveAuthenticatedCustomer(Authentication authentication) {
		if(authentication instanceof CasAuthenticationToken){
			String userName = authentication.getName();
			Customer customer = customerService.readCustomerByUsername(userName);
			return customer;
		}
        return null;
    }
}
